package com.framework.utils.util;


/**
 * 
 * <p>Description:字符串工具类</p> 
 * @since 2016年10月9日
 * @author LiZhu
 * @version 1.0
 * <p>Company:Mopon</p>
 * <p>Copyright:Copyright(c)2014</p>
 */
public class StringUtils {
	public static final String EMPTY = null;

	/**
	 * 
	 * 方法用途: 判断字符串是否为空或者为空字符串<br>
	 * 实现步骤: <br>
	 * @param value
	 * @return null或空字符串返回true;否则false
	 */
	public static boolean isEmpty(String value) {
		return (value == null || "".equals(value.trim()));
	}

	public static boolean isBlank(String value) {
		return isEmpty(value);
	}

	public static boolean isNotBlank(String value) {
		return !isEmpty(value);
	}
	
	/**
	 * 
	 * 方法用途: 替换字符串中的内容<br>
	 * 实现步骤: <br>
	 * @param inString
	 * @param oldPattern
	 * @param newPattern
	 * @return
	 */
	public static String replace(String inString, String oldPattern, String newPattern) {
		if (!hasLength(inString) || !hasLength(oldPattern) || newPattern == null) {
			return inString;
		}
		StringBuilder sb = new StringBuilder();
		int pos = 0; // our position in the old string
		int index = inString.indexOf(oldPattern);
		// the index of an occurrence we've found, or -1
		int patLen = oldPattern.length();
		while (index >= 0) {
			sb.append(inString.substring(pos, index));
			sb.append(newPattern);
			pos = index + patLen;
			index = inString.indexOf(oldPattern, pos);
		}
		sb.append(inString.substring(pos));
		// remember to append any characters to the right of a match
		return sb.toString();
	}
	
	public static boolean hasLength(String str) {
		return hasLength((CharSequence) str);
	}
	
	public static boolean hasLength(CharSequence str) {
		return (str != null && str.length() > 0);
	}
}
